<!--观点详情-->
<template>
  <div class="all bg1">

    <scroller class="content">

      <template v-if="data">
        <div class="row acenter mb30">


          <div class="row acenter" @click="userClick">
            <LImage class="img-head" :src="data.avatar"></LImage>

            <div class="column mr10">
              <text class="font32 fontz text2 mb2">{{data.nickName}}</text>
              <text class="font24 fontz text3">{{data.time}}</text>
            </div>
          </div>

          <div class="all"></div>
          <div v-if="!isUser" class="but-dingyue" :class="[data.isSubscriber==1 ? 'no-b1' : 'main-b1']" @click="dingyueClick">
            <LImage v-if="data.isSubscriber==0" class="img-dingyue" :src="Config.img('dingyue.png')"></LImage>
            <text class="font26 fontz" :class="[data.isSubscriber==1 ? 'text3' : 'main-t1']">{{data.isSubscriber==1 ? T('已订阅') : T('订阅')}}</text>
          </div>
        </div>

        <text class="font26 text2 lebel" @click="infoClick">{{data.content}}</text>
      
        <!-- <text class="font26 text3 tRight">{{data.viewsNum+' '+T('人预览')}}</text> -->
      </template>
    </scroller>


    <div class="bottom bg2">
      <div class="bottom-but" @click="httpUnlike">
        <LImage v-if="data.isLike==1" class="img-zan" :src="Config.img('zan_.png')"></LImage>
        <LImage v-else class="img-zan" :src="Config.img('zan.png')"></LImage>
        <text class="font30" :class="[data.isLike==1 ? 'udRed-t1' : 'text3']">{{T('点赞')+'('+data.likeNum+')'}}</text>
      </div>
      <div class="bottom-but" @click="shareClick">
        <LImage class="img-zan" :src="Config.img('fenxiang.png')"></LImage>
        <text class="font30 text3">{{T('分享')}}</text>
      </div>
    </div>
  </div>
</template>


<script>

//组件
import VPoint from '@/point/view/VPoint.vue' 

//功能
import jhttps from "@/_js/https";
import jconfig from "@/_js/config";
import jmodal from "@/_js/modal";
import jmath from "@/_js/math";
import jtime from "@/_js/time";
import jnavigator from "@/_js/navigator";
import jbroadcast from "@/_js/broadcast";

const weexFunction = weex.requireModule("WeexFunction");
const dom = weex.requireModule("dom");

import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {

  components: {
    VPoint,
  },

  data() {
    return {
      T:T,
      Config:jconfig,
      
      id:'',
      data:undefined,
    };
  },

  created() {

    this.id = jnavigator.getParam('id');
    this.isUser = jnavigator.getParam('isUser');

    this.httpQueryPointDetails();
  },

  methods: {

    /********************************* HTTP*/
    //http观点详情
    httpQueryPointDetails() {

      jmodal.showLoad();
      var param = {'id':Number(this.id)};
      jhttps.post("point/queryPointDetails",param,true,(data) => {

        jmodal.hideLoad();
        if (data.status == 200) {
          
          data = data.data;

          var timestamp = new Date().getTime();
          var cha = timestamp - data.createTime;
          if (cha < 30000) {
            data.avatar == T('刚刚');
          } else if (cha < 60000) {
            data.avatar == T('1分钟前');
          } else {
            data.time = jtime.getTime(data.createTime, 'y/M/d H:m');
          }
          data.avatar = data.avatar ? data.avatar : jconfig.img('touxiang.png');
          this.data = data;
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    //http点赞
    httpUnlike() {
      if(!jconfig.forceLogin()) return;

      jmodal.showLoad();
      var param = {'id':Number(this.data.id)};
      var url = this.data.isLike == 1 ? 'point/unlike' : 'point/giveALike';
      jhttps.post(url, param,true,(data) => {

        jmodal.hideLoad();
        if (data.status == 200) {

          var id = this.data.id;
          var isLike = this.data.isLike == 1 ? 0 : 1;
          var likeNum = isLike == 1 ? jmath.jia(this.data.likeNum, 1) : jmath.jian(this.data.likeNum, 1);
          likeNum = likeNum < 0 ? 0 : likeNum;
          this.data.isLike = isLike;
          this.data.likeNum = likeNum;
          jbroadcast.send('PointUnlike', {id, isLike, likeNum});
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    //http订阅
    httpSubscribe() {
      jmodal.showLoad();
      var param = {'userId': this.data.userId};
      jhttps.post("point/subscribe", param, true,(data) => {
        jmodal.hideLoad();
        if (data.status == 200) {
          
          var isSubscriber = 1;
          var endTime = new Date().getTime() + 2592000000;
          this.data.isSubscriber = isSubscriber;
          this.data.endTime = endTime;
          jbroadcast.send('PointSubscribe', {isSubscriber, endTime});
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    //http取消订阅
    httpCancelSubscribe() {
      jmodal.showLoad();
      var param = {'userId': this.data.userId};
      jhttps.post("point/cancelSubscribe", param, true,(data) => {
        jmodal.hideLoad();
        if (data.status == 200) {
          var isSubscriber = 0;
          var endTime = this.data.endTime;
          this.data.isSubscriber = isSubscriber;
          jbroadcast.send('PointSubscribe', {isSubscriber, endTime});
        } else {
          jmodal.toast(data.msg);
        }
      });
    },

    /********************************* 点击*/
    //用户信息
    userClick() {
      var param = {'userId':this.data.userId};
      jnavigator.open('', "follw/UFollwManInfo",param);
    },
    
    //订阅
    dingyueClick(){
      if(!jconfig.forceLogin()) return;

      if(this.data.isSubscriber==1) {

        var parm = {'title':T("取消订阅"),
                  'message':T("取消订阅后，将无法收到该用户实时观点信息通知")+'。'};
        jmodal.confirm(parm, (bool)=>{
          if (bool == "true") {
            this.httpCancelSubscribe();
          }
        });
        return;
      }

      var timestamp = new Date().getTime();
      if (this.data.endTime && this.data.endTime > timestamp) {

        var time = jtime.getTime(this.data.endTime);
        var parm = {'title':T("开启订阅"),
                    'message':T("开启订阅后，将收到该用户的实时观点信息通知")+'。'+T('您已支付过费用，此次订阅不会重复收费')+','+T('费用')+this.data.expense+'VTN/'+T('月')+'。'};
        jmodal.confirm(parm, (bool)=>{
          if (bool == "true") {
            this.httpSubscribe();
          }
        });
        return;
      }

      var parm = {'title':T("开启订阅"),
                  'message':T("开启订阅后，将收到该用户的实时观点信息通知")+'，'+T('费用')+this.data.expense+'VTN/'+T('月')+'。'};
      jmodal.confirm(parm, (bool)=>{
        if (bool == "true") {
          this.httpSubscribe();
        }
      });
    },

    //分享
    shareClick() {
      weexFunction.shareApp();
    }
  },
};

</script>

<style src="@/_css/style.css" ></style>
<style scoped>
.content {
  overflow: hidden;
  padding: 40px;
}
.img-head {
  width: 70px;
  height: 70px;
  border-radius: 35px;
  margin-right: 20px;
}
.but-dingyue {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  height: 50px;
  border-radius: 25px;
  border-width: 2px;
  padding: 0 20px;
  margin-right: 10px;
}
.img-dingyue {
  width: 25px;
  height: 25px;
}

.scroller {
  flex: 1;
}
.lebel {
  min-height: 400px;
  line-height: 40px;
}

.bottom {
  flex-direction: row;
  height: 160px;
  background: #151A2A;
  box-shadow: 0px -1px 0px 0px #2F364B;
}
.bottom-but {
  flex: 1;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0 30px 60px 30px;
}
.img-zan {
  width: 36px;
  height: 36px;
  margin-right: 14px;
}
.img-fen {
  width: 36px;
  height: 36px;
}
</style>